#!/usr/bin/perl -w
use File::Copy qw(copy cp);
use Cwd;

chmod 0777, 'sim_config';
$SIM_CFG = qx(sim_config);
#$SIM_CFG =~ s/\s//g;
@SIM_CFG = split/ /,$SIM_CFG;
#@SIM_CFG = split/\+/,$SIM_CFG[4];
foreach(@SIM_CFG){
    if(/libs/g){
        $LIB_PATH .= "$_\n";
    }
    if(/define/g){
        $DEF_CFG .= "$_\n";
    }

    #print"$_\n";
}
#print "$DEF_CFG\n";
#print "$LIB_PATH\n";

open(MODULE_FILE_LIST,"<module_file_list") or die "Open module_file_list failed: $!";
open(VERDI_FILE_LIST,">verdi_file_list");
@file_line=<MODULE_FILE_LIST>;
foreach(@file_line){
    chomp($_);
    say VERDI_FILE_LIST "$_";
    }
say VERDI_FILE_LIST "$LIB_PATH";
close MODULE_FILE_LIST;
close VERDI_FILE_LIST;

chomp($DEF_CFG);
system "verdi -sv tbtop.v -f verdi_file_list  $DEF_CFG -ssf tb.fsdb &"
